home *** CD-ROM | disk | FTP | other *** search
- { ========================================================================== }
- { Unit: CLPARSER (formerly PARSER) Command_Line_Parser }
- { ========================================================================== }
- { }
- { }
- { !!!! !!!! !!!!!! }
- { !! !! !! !! !! }
- { !! ! !! !! !! !!!! !! !!! !!!!! !!!!! !! !!! }
- { !! !! !! !! !! !!! !! !! !! !! !! !!! !! }
- { !! !! !!!!! !!!!! !! !! !!! !!!!!!! !! !! }
- { !! ! !! ! !! !! !! !! !!! !! !! }
- { !! !! !! !! !! !! !! !! !! !! !! !! !! }
- { !!!! !!!!!!! !!!! !!! !! !!!! !!!!! !!!!! !!!! }
- { }
- { }
- { ========================================================================== }
- { }
- { Description: Parser provides access to commandline arguments and }
- { switches by separating them into seperate arrays. }
- { }
- { Modification History: }
- { }
- { PARSER 04/07/89 Version 1.0 }
- { }
- { OPARSER 04/14/89 Version 1.1 (TEST OOPS style OBJECT unit) }
- { }
- { CLPARSER 06/26/89 Version 2.0 (OOPS OBJECT unit) }
- { }
- { CLPARSER 07/26/89 Version 2.1 }
- { }
- { Fixed a bug in the Argument.Find method }
- { that allowed a target string longer than }
- { the item string to match if the first }
- { part of the target matched the item. }
- { }
- { Added the PFile type. This is a parameter }
- { file parser that fills the list with }
- { valid parameters from the file. Comments }
- { are definable and skipped. White space }
- { (tabs, spaces and blank lines) is ignored, }
- { also. }
- { }
- { This is the first version released to }
- { bulletin boards. (TP5.5) }
- { }
- { CLPARSER 08/19/89 Version 2.11 }
- { }
- { Removed external library references and comp- }
- { iled the shareware version as overlay-able. }
- { }
- { CLPARSER 10/01/90 Version 3.0 }
- { }
- { Re-implemented the list as entirely heap }
- { resident. When the object is collapsed it will }
- { now reclaim all heap memory used. I found that }
- { in many cases the amount of heap stolen was TOO }
- { MUCH! }
- { }
- { CLPARSER 04/06/91 Version 3.1 }
- { }
- { This version is compatible with TP 6.0. }
- { Several fundamental changes were made to this }
- { unit which changed the programmer interface. }
- { }
- { 1. Automatic variables have been dropped. You }
- { must declare and initialize all objects used }
- { in your own source. }
- { }
- { 2. Typed pointers to the object have been added }
- { to allow dynamic allocation of objects. }
- { }
- { 3. The ERASE method has been renamed DONE. This }
- { aligns CLPARSER with "standard" nomenclature }
- { used by OPro and TVision. }
- { }
- { ie. }
- { }
- { Var }
- { pArg, pSw : pArgument; }
- { }
- { begin }
- { pArg := New( pArgument, Init( }
- { NormalChars-Switches)); }
- { pSw := New( pArgument, Init(Switches)); }
- { }
- { if pArg^.Count = ...... }
- { .... }
- { .... }
- { }
- { Dispose( pArg, Done ); }
- { Dispose( pSw, Done ); }
- { end; }
- { }
- { 4. The HELP object has been added. }
- { }
- { }
- { CLPARSER 02/29/92 Version 3.2 }
- { }
- { This version was modified to include a pointer }
- { to a CARGO area. The cargo can be any thing. }
- { The ItemRecord definition now includes 2 new }
- { declarations: Cargo and CargoLen. Cargo is a }
- { pointer and CargoLen is a long integer. }
- { }
- { ========================================================================== }
- { Copyright (c) 1989, 1992 by Greg L. Truesdell }
- { All Rights Reserved }
- { ========================================================================== }
- {*} {.A-,B-,D-,E-,F-,I-,L-,N-,O-,R-,S-,V-} {*}
- { ========================================================================== }
- Unit CLParser;
-
- { ========================================================================== }
- INTERFACE
- { ========================================================================== }
-
- Type
- CharSet = Set of Char;
-
- { argument record }
-
- ItemRecordP = ^ItemRecord;
- ItemRecord = Record
-
- Item :^String; { parsed item String }
- ItemLen : Byte; { length + 2 of item String }
- Posn : LongInt; { position }
- Cargo : Pointer; { data record pointer }
- CargoLen : LongInt; { size of data record }
- NextItem : ItemRecordP; { pointer to the next node in list }
- PrevItem : ItemRecordP; { pointer to previous node in list }
-
- end;
-
- { list is the data structure }
-
- pClpList = ^clpList;
- clpList = object
-
- firstitem : ItemRecordP; { pointer to first record in list }
- currentitem : ItemRecordP; { pointer to current record in list }
- lastitem : ItemRecordP; { pointer to last record in list}
- items : Word; { number of items in the list }
- index : Word; { current item number }
-
- Constructor Init;
- Destructor Done;
- Function Add( add_item: String; locn: LongInt ) : Boolean;
- Function AddCargo( Add_Item: String; Locn : LongInt;
- pCargo : Pointer; CargoSize: Word ) : Boolean;
- Function Next : String;
- Function NextCargo( var pCargo : Pointer; var CargoSize : LongInt ) : String;
- Function Prev : String;
- Function PrevCargo( var pCargo : Pointer; var CargoSize : LongInt ) : String;
- Function Count : Word;
- Function Position : LongInt;
- Procedure Reset;
-
- end;
-
- { help is a list of help lines }
- pHelp = ^Help;
- Help = object(clpList)
-
- ScreenLines : Byte;
- LineCount : Byte;
-
- Constructor Init( nLines : Byte );
- Function ReadFile( filename : String ) : Boolean;
- Procedure Display;
-
- end;
-
- { argument is a list of arguments }
-
- pArgument = ^Argument;
- Argument = object(clpList)
-
- more : Boolean;
-
- Constructor Init( LegalChars: CharSet );
- Function Find( target : String ): String;
- Function Overflow: Boolean;
-
- end;
-
- { Environ is a list of environment variables }
-
- pEnviron = ^Environ;
- Environ = object(Argument)
-
- Constructor Init;
-
- end;
-
- { wild is a special list of filenames }
-
- pWild = ^Wild;
- Wild = object(argument)
-
- Constructor Init( filemask: String; attributes: Word );
-
- end;
-
- { pfile is a special list of parameter file entries }
- pPFile = ^PFile;
- PFile = object(argument)
-
- Constructor Init( filename: String; comment: CharSet );
-
- end;
-
- Const
-
- { default argument triggers }
- Switches : CharSet = ['/','-','+']; { Set of switch Characters }
- NormalChars : CharSet = [#32..#127]; { Set of normal Chars }
- CmdTail : String = '';
-
- { ========================================================================== }
- IMPLEMENTATION
- { ========================================================================== }
-
-